<!DOCTYPE html>
<html>
<head>
	<title>注册页面</title>
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="keywords" content="注册页面" />
	<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
	<link href="__STATIC__/home/login/css/font-awesome.min.css" rel="stylesheet" type="text/css" media="all">
	<link href="__STATIC__/home/login/css/snow.css" rel="stylesheet" type="text/css" media="all" />
	<link href="__STATIC__/home/login/css/style.css" rel="stylesheet" type="text/css" media="all" />
	<link rel="stylesheet" href="__STATIC__/home/js/layer/theme/default/layer.css">
	<link rel="shortcut icon" href="__STATIC__/home/index/picture/2.png" type="image/x-icon">
<style>
	.sp1{
		color: white;
	}
</style>

</head>
<body>
<div class="snow-container">
	<div class="snow foreground"></div>
	<div class="snow foreground layered"></div>
	<div class="snow middleground"></div>
	<div class="snow middleground layered"></div>
	<div class="snow background"></div>
	<div class="snow background layered"></div>
</div>

<div class="top-buttons-agileinfo">
	<a href="{:url('home/users/login')}">登录</a><a href="#" class="active">注册</a><a href="{:url('home/index/index')}">返回首页</a>
</div>
<h1>注册</h1>
<div class="main-agileits">
	<!--form-stars-here-->
	<div class="form-w3-agile">
		<h2 class="sub-agileits-w3layouts">用户注册</h2>
		<div class="div1">
			<input type="text" class="mobile" name="mobile" placeholder="手机号码" />
		</div>
		<div class="div2">
			<input type="text" class="verify_code"  name="verify_code" placeholder="验证码" />
		</div>
		<div class="div3">
			<input type="password" class="user_pwd"  name="user_pwd" placeholder="密码" />
		</div>
		<div class="div4">
			<input type="password" class="user_pwd1"  name="user_pwd1" placeholder="再次输入密码" />
		</div>
		<a href="javascript:;">
		<div class="submit-w3l" onclick="submit(this)" >
			<span type="button" id="btn"  class="sp1">发送验证码</span>
			<!--<button id="btn" onclick="submit(this)" >发送验证码</button>-->
		</div>
		</a>
		<div class="submit-w3l">
			<input type="submit" class="btn" value="注册" />
		</div>
	</div>
</div>
<div class="copyright w3-agile">
	<p> © 2017 Internship Sign In & Sign Up Form . All rights reserved | Design by chuangxuexi </p>
</div>

</body>

<script src="__STATIC__/home/js/jquery.min.js"></script>
<script src="__STATIC__/home/js/layer/layer.js"></script>

<script>
    function submit(obj) {
        $.ajax({
            'type':'post',
//            'url':"http://127.0.0.1/new_tp5/public/index.php/home/users/send_sms_code",
            'url':"{:url('home/users/send_sms_code')}",
            'data':{
                'mobile' : $("input[name='mobile']").val()
            },
            'success':function (result) {
                console.log(result);
            },
            'error':function () {
                console.log('error');
            }
        })
    }

    $(document).ready(function () {
        $(".btn").click(function () {

            var data = {};
            data.mobile = $(".mobile").val();
            data.verify_code =$(".verify_code").val();
            data.user_pwd =$(".user_pwd").val();
            data.user_pwd1 =$(".user_pwd1").val();

            if(data.mobile ==""){
                layer.tips('手机号不能为空', '.mobile', {
                    tips: 3
                });
                return false;
            }
            if(!/^((\d{3}-\d{8}|\d{4}-\d{7,8})|(1[3|5|7|8][0-9]{9}))$/.test(data.mobile)){

                layer.tips('请输入正确手机号', '.mobile', {
                    tips: 3
                });
                return false;
            }
            if(data.verify_code == ""){
                layer.tips('验证码不能为空', '.verify_code', {
                    tips: 3
                });
                return false;
            }
            if(data.user_pwd == ""||data.user_pwd1 == ""){
                layer.tips('密码不能为空', '.user_pwd', {
                    tips: 3
                });
                return false;
            }
            if(data.user_pwd != data.user_pwd1){
                layer.tips('两次密码不相同', '.user_pwd1', {
                    tips: 3
                });
                return false;
            }

			$.post("{:url('home/users/addUser')}",data,function (data) {

			    if(data == 0){
                    layer.msg('注册成功！！', {icon: 1});
                    setTimeout(function(){
                        window.location.href=("{:url('home/index/index')}")
                    },2000);

				}else if(data == 1){
                    layer.msg('账号已存在！！', {icon: 5});
				}else if(data == 2){
                    layer.msg('验证码错误！！', {icon: 5});
				}else if(data == 3){
                    layer.msg('注册失败！！', {icon: 5});
				}

            })

        })


    })



    function btn(obj) {
        $.ajax({
            'type':'post',
            'url':"http://127.0.0.1/new_tp5/public/index.php/home/users/register",
//            'url':"{:url('home/users/register')}",
            'data':$("#forms").serialize(),
            'success':function (result) {
//                console.log(result);
                window.location.href=("{:url('home/users/index')}");
            },
            'error':function () {
                console.log('error');
            }
        })
    }
</script>
</html>